package com.yaoxun.bored.service.sys.role;

import java.util.List;
import java.util.Set;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yaoxun.bored.common.BaseService;
import com.yaoxun.bored.mapper.sys.role.RoleMapper;
import com.yaoxun.bored.model.sys.role.Role;
import com.yaoxun.bored.model.sys.role.SessionRole;

@Service
public class RoleService extends BaseService<Role> {
	
	@Inject
	private RoleMapper roleMapper;
	
	@Transactional(readOnly=true)
	public List<SessionRole> selectByUserId(Integer userId) {
		return roleMapper.selectByUserId(userId);
	}
	
	@Transactional(readOnly=true)
	public Set<String> selectAuthCode(List<SessionRole> roles) {
		if(roles != null && roles.size() > 0) {
			Integer[] roleIds = new Integer[roles.size()];
			for(int i=0; i<roles.size(); i++) {
				roleIds[i] = roles.get(i).getRoleId();
			}
			return roleMapper.selectAuthCodes(roleIds);
		}
		return null;
	}
	
}
